# This Python file uses the following encoding: utf-8


import pymongo
import redis

class DB:
        __myMongoDB=''
        __myRedisDB=''

        def __init__(self):
                pass

        def getMongoDB(self):
                #链接数据库，
                if self.__myMongoDB == '':
                        try:
                            self.__myMongoDB = pymongo.MongoClient('mongodb://localhost:27017/',connect=False)
                        except:
                            print("mongodb is error")
                        else:
                            print('mongodb is connected...')
                return self.__myMongoDB

        def getRedisDB(self):
                if self.__myRedisDB == '':
                    try:
                        pool = redis.ConnectionPool(host='localhost', port=6379, db=5, decode_responses=True)
                        self.__myRedisDB = redis.Redis(connection_pool=pool)
                    except:
                        print("redisdb is error")
                    else:
                        print('redisdb is connected...')
                return self.__myRedisDB

ObjLink = DB()
